package com.yudylaw.algorithm;

public class KuaiSuSort {

	public static void main(String[] args) {
		int[] nums = {12,2,35,33,555,33,0,103,1023,1003,2333,33,290};
		quickSort(nums,0,nums.length-1);
		for (int i = 0; i < nums.length; i++) {
			System.out.println(nums[i]);
		}
	}
	
	public static void quickSort(int[] sortable,int begin,int end){
		if(begin>=end)return;
		int m = ( begin + end ) /2;
		int tmp = sortable[end];
		sortable[end] = sortable[m];
		sortable[m] = tmp;
		int j = begin;//j,i mast begin from start position
		for(int i=begin;i<=end-1;i++){
			if(sortable[i]<sortable[end]){
				tmp = sortable[i];
				sortable[i] = sortable[j];
				sortable[j] = tmp;
				j++;
			}
		}
		tmp=sortable[j];
		sortable[j]=sortable[end];
		sortable[end]=tmp;
        quickSort(sortable,begin,j);
        quickSort(sortable,j+1,end);
	}
	
}
